<template>
	<view class="my_apply">
		<xbd-pages-content title="我的审批">
			<template #content>
				<view class="content">
					<view class="choose">
						<text>历史审批申请表：{{total}}张</text>
					</view>
					<uni-list :border="false">
						<view class="">
							<xbd-car-card v-for="item in showList" :key="item._id" :myInfo="item"
								@clickUseCarCard="details(item._id)"></xbd-car-card>
						</view>
						
						<xbd-null-list v-if="!showList.length"></xbd-null-list>

						<xbd-loading-more :status-num="statusNum" :is-load-more="isLoadMore"></xbd-loading-more>
					</uni-list>

				</view>
			</template>
		</xbd-pages-content>
	</view>
</template>

<script>
	import { UseCar } from '@/api/index.js';

	export default {
		data() {
			return {
				visible: false,
				visible1: false,
				statusNum: 0,
				isLoadMore: false,
				total: 0,
				showList: [],
				queryInfo: {
					diff: 'audit',
					page: 1,
					perpage: 10
				}
			};
		},
		methods: {
			async getList() {
				try {
					this.$showLoading('加载中');
					const res = await UseCar.getUseCarList(this.queryInfo);
					console.log(res)
					uni.hideLoading();
					this.total = res.data.total;
					this.showList = res.data.dataList.filter(item => item.apply_state !== "cancelled")
					if (res.data.dataList.length === this.queryInfo.perpage) {
						this.isLoadMore = true;
						this.statusNum = 2;
					}
					console.log('list', res)
				} catch (e) {
					uni.hideLoading();
					console.log(e);
				}
			},
			// 加载更多
			loadmore() {
				if (this.visible || this.visible1) {

				} else {
					this.queryInfo.page++;
					this.statusNum = 1;
					this.isLoadMore = true;
					this.loadmoreList();
				}

			},
			// 加载数据
			async loadmoreList() {
				try {
					// this.$showLoading('加载中');
					const res = await UseCar.getUseCarList(this.queryInfo);
					uni.hideLoading();
					if (res.success) {
						this.total = res.data.total;
						this.showList = this.showList.concat(res.data.dataList);
						if (res.data.dataList.length === this.queryInfo.perpage) {
							this.statusNum = 2;
						} else {
							this.statusNum = 0;
						}
					} else {
						this.queryInfo.page--;
						this.statusNum = 0;
					}
				} catch (e) {
					uni.hideLoading();
					this.queryInfo.page--;
					console.log(e);
				}
			},
			details(id) {
				uni.navigateTo({
					url: `../myApply/details?msg=2&id=${id}&title=审批详情`,
				})
			}

		},
		computed: {

		},
		onShow(){
			this.queryInfo.page = 1
			this.getList()
			// 强制刷新回到顶部
			uni.pageScrollTo({
			    scrollTop: 0,
			});
		},
		onLoad() {
			// this.getList()
			// uni.$on('refresh', this.eventCallback);
			// uni.$on('carPassed', this.eventCallback);
		},
		onUnload() {
			// uni.$off('refresh');
			// uni.$off('carPassed');
		},
		// 触底触发
		onReachBottom() {
			// 当下拉组件显示状态 并且显示不是没有数据了 时才进行下拉加载
			if (this.isLoadMore && this.statusNum !== 0 && this.total/10 >this.queryInfo.page) {
				this.loadmore();
			}
			if(this.total/10 >this.queryInfo.page){
				
			}else{
				this.isLoadMore = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-list {
		background-color: #f8f8f8;
	}

	.choose {
		// height: 105px;
		box-sizing: border-box;
		padding: 20px 50rpx;
		font-size: 14px;
		color: #999999;
		background-color: #F8F8F8;
	
	}
</style>
